import os
import pandas as pd
from datetime import datetime
import ccxt

class GetData():
    def __init__(self, save_path):
        self.save_path = save_path
        self.origin_data = None
        self.data = None

    def load(self):
        # 判断data.csv文件是否存在
        if os.path.exists(self.save_path):
            df = pd.read_csv(self.save_path)
            if not df.empty:  # 判断文件是否有数据
                self.data = df
            
            self.origin_data = self.data[["t", "open", "close", "high", "low", "volume"]]
            self.data = self.data[["open", "close", "high", "low", "volume"]]
            self.close_max = max(self.data.close)
            self.close_min = min(self.data.close)
            # Normalization
            self.data = self.data.apply(lambda x: (x - min(x)) / (max(x) - min(x)))
        else:
            self.initData()
            self.load()

    def initData(self):
        if os.path.exists(self.save_path):
            currect_time = datetime.now()
            os.rename(self.save_path, self.save_path + '.bakup' + currect_time.strftime('%Y%m%d_%H%M%S'))
        


        